<template>
    <div class="login-all-box">
        <div class="title-box">
            <img src="../assets/images/logo.png" alt="logo" title="logo" class="logo">
            <span class="title">高校调查问卷管理系统</span>
        </div>
        <div class="login-box">
            <div class="login-box-item">
                <span class="login-title">用户登录</span>
                <span class="login-item">
                    <input type="text" class="username" placeholder="请输入用户名" v-model="username">
                </span>
                <span class="login-item">
                    <input type="password" class="password" placeholder="请输入密码" v-model="password">
                </span>
                <span>
                    <button class="login-goLogin button-go" @click=goRegister()>
                        登录
                    </button>
                    <!-- <router-link to="#" class="login-goLogin"> 登录</router-link> -->
                    <!-- <button class="login-goRegister">
                            还没有账户，登记注册
                        </button> -->
                    <router-link to="register" class="login-goRegister button-go"> 还没有账户，点击注册</router-link>
                </span>
            </div>
        </div>
    </div>
</template>
<script>
    import axios from "axios"
    import qs from "qs"
    export default {
        data() {
            return {
                    username: "",
                    password: "",
            }
        },
        methods: {
            goRegister() {
                console.log("res.data")
                console.log(this.username)
                console.log(this.password)
                axios({
                    method: "post",
                    url: "http://110.40.154.136:8080/user/login",
                    data:
                    qs.stringify(
                        {
                        username: this.username,
                        password: this.password
                    }),
                    headers: {
                        // 'X-Requested-With': 'XMLHttpRequest',    
                        // "Content-Type": "multipart/form-data",
                        'Content-Type':'application/x-www-form-urlencoded'
                    },
                }).then((res) => {
                    console.log(res.data)
                    console.log(res.data.msg)
                    if (res.data.msg=="操作成功") {
                        console.log('/afterloginIindex')
                        this.goRouterRegister()
                        
                    }

                })
            },
          
            goRouterRegister(){
                console.log('/afterloginIindex')
                this.$router.push({ path:'/afterloginIindex'})
                // this.$router.repalce('/afterloginIindex')
            }

        }
    }

</script>
<style src="../assets/css/login.css" scoped>
    /* @import "../assets/css/login.css"; */
</style>